Bike Trips Sample Application: Using the XMLConnector Component in Flash MX Professional 2004
Table of Contents
- Introduction
- Getting Started: Examining the Bike Trips Application and Its Data
- Configuring the Application to Use the XMLConnector Component
- Binding XML Data to a ComboBox Component
- Creating ComboBox Labels Using XML Data
- Displaying and Updating a Trip Description in a TextArea Component
- Displaying and Updating a Formatted Cost in a TextInput Component
- Displaying and Updating a Graphic in a Loader Component
- Summary and Related Articles and Resources
Displaying and Updating a Formatted Cost in a TextInput Component
- Save XMLConnector_step3.fla as XMLConnector_step4.fla.
- Open the Components panel. Drag an instance of the TextInput component onto the Stage and drop it below the word "Cost."
-
Open the Property inspector for this new TextArea instance and set the following values:
- Instance name: tiCost
- Width: 135
- Editable: false
Note: While you can set default text for a TextInput component, do not do so here because the xcTrips XMLConnector component will provide these values dynamically, and users will specify them using the cbTrips ComboBox.
-
Expose the cost property from trip:Array in xcTrips as an available binding:
- Select xcTrips.
- Open the Component Inspector panel and select the Bindings tab.
- Click the Plus (+) button to add a new data binding, exposing the imported XML data schema, which you previously bound to xcTrips.
- Select the cost property in the array of trip objects (called trip:Array) from the schema and click OK.
- You should now see the results.trips.trip.[n].cost property of xcTrips listed as a binding available from xcTrips.
-
Attach the newly exposed binding to the text property of tiCost TextInput component:
- Select the results.trips.trip.[n].cost binding from the Bindings tab in the Component Inspector panel for the xcTrips XMLConnector component instance.
- In the Bindings property grid, below the binding, set the direction property for this binding to "out."
- Select the bound to property, and click the magnifying glass button.
-
In the Bound To dialogue, set the following:
- Component Path: TextInput <tiCost>
- Schema Location: text : String
- Click OK.
- Select Control > Test Movie to test your application. Notice that the cost for the first trip now appears in the tiCost TextInput component. However, if you select a different value in cbTrips, the cost displayed in tiCost does not yet update. Notice also that the cost is unformatted.
-
Use the selectedIndex property of the cbTrips ComboBox component to make the currently selected row determine the cost displayed in the tiCost TextInput component. Because data bindings dynamically update when bound values change, the cost will update whenever the trip name changes:
- Select the xcTrips XMLConnector component.
- Open the Component Inspector panel and select the Bindings tab.
- Select the results.trips.trip.[n].cost binding.
- Select the Index for 'trip' property, and click the magnifying glass button.
-
In the Bound Index dialogue, uncheck "use a constant value" and set the following:
- Component Path: cbTrips ComboBox
- Schema Location: selectedIndex : Number
Note: At this point in the last series of steps, set a default value of zero for cbTrips' selectedIndex property, to ensure data binding occurs when the application first loads, just as though the user had selected that index of the ComboBox. You do not need to repeat this here, as it's effective for all components bound to the cbTrips ComboBox.
-
Format the data in the tiCost TextInput component so that it appears as United States currency:
- Select the tiCost TextInput component.
- Open the Component Inspector and select the Bindings tab.
- Set the formatter property to "Compose String."
- Select formatter options, and press the magnifying glass button.
- In the Compose String dialogue, set the following value: $<.>.00.
- Click OK.
Note: When using formatters, refer to dynamic values using brackets. If a particular field receives complex data, use the property name in brackets. If a particular field receives simple data, such as a String or Number (as you do here), use a single dot (".") in brackets to refer to the actual value received. You then "compose" the rest of the string around those dynamic values however you wish (as you did above).
Note: Flash MX Professional 2004 has tools and methods to support localized data formatting. However, that discussion is beyond the scope of this tutorial.
- Select Control > Test Movie to test your application. You should see the trip "Napa," its description, and its cost, formatted as "$1095.00" as your application loads. As you change the trip name, the cost and description should automatically update.
- Save your changes to XMLConnector_step4.fla.